$(function () {
    getProductData(1,0);
});
var pageNum = 1;
var productType=0;
function getProductData(page,product_type) {
    if (page==null || page=='')
        page = pageNum;
    if (product_type==null||product_type=='')
        product_type = productType;
    let data = myAjax('/product', 'post', {"product_type":product_type,"page":page}, 'json');
    console.log(data);
    sessionStorage.setItem("productData",JSON.stringify(data));
    $(".pdt_type").html("");
    $.each(data.productTypes,function (i,producttype) {
        $(".pdt_type").append("<div onclick='getProductData(1,"+producttype.id+")'>"+ producttype.name +"</div>");
    });
    $(".pdt_details").html("");
    $.each(data.products,function (i,product) {
        $(".pdt_details").append("<div onclick='redirectProductDetails("+ i +")'><div><img src="+product.photo+" height='90%' width='90%'/></div><div class='name'>"+product.name+"</div><div class='type'>"+product.productType.name+"</div><div><div class='price'>价格：</div><div class='num'>"+product.price+"</div></div></div>");
    });
};
function redirectProductDetails(i) {
    sessionStorage.setItem("pdti",i);
    window.location.href = "/html/front/productdetails.html";
}